//南航明珠商城-限时统一折扣管理.js

function search() {
	var startDate = $('#startDate').val();
	var endDate = $('#endDate').val();
	if ((startDate.length != 0 && startDate != '')
			&& (endDate.length != 0 && endDate != '')) {
		var startTime1 = startDate.slice(0, 4) + startDate.slice(5, 7)
				+ startDate.slice(8, 10);
		var endTime1 = endDate.slice(0, 4) + endDate.slice(5, 7)
				+ endDate.slice(8, 10);
		var timeValue1 = endTime1 - startTime1;
		if (timeValue1 < 0) {
			layer.alert("结束时间必须大于或等于开始时间!");
			return;
		}
	}
	document.getElementsByName("name")[0].value = document
			.getElementsByName("name")[0].value.trim();         
	$("#search_form").submit();
}
function toIsEmpty() {
	$("#startDate").val("");
	$("#endDate").val("");
	document.getElementsByName("name")[0].value = "";
	document.getElementsByName("prodNo")[0].value = "";
}

function addProduct(){
	    var index = layer.open({
	        type: 2,
	        title: "发布新品",
	        scrollbar: false,
	        content: path+"/new_arrival_product/to_add_product",
	        area: ['800px', '600px']
	    });
}
function delProduct(){
	var ids="";
	$("[name=chk]:checked").each(function(){
	var id=$(this).val();
	ids+=id+",";
	})
	if(ids.length==0){
	layer.alert("请选择要删除的商品！");
	return false;
	}
	layer.confirm("确定批量删除?",function(){
		layer.closeAll('dialog');
		var layer_load_window = layer.load(2); 
		var url=path+"/new_arrival_product/delete_by_id?ids="+ids;
		$.ajax({
			url : url,
			cache : false,
			dataType : 'text',
			error : function() {
				layer.alert("操作失败！");
	       },
			success : function(data) {
			    if(data == "success"){
				    layer.msg('删除成功!',{icon:1,time:1000},function(){
				    	$("#search_form").submit();
				    });
			   }else if (data == "fail") {
				   layer.alert("操作失败！");
			   } else{
				layer.alert(data);
			   }
			},
			complete: function(XMLHttpRequest, textStatus) {
				layer.close(layer_load_window);
			}
		  })		
		});
}
function deleteProduct(id){
	layer.confirm("确定要删除此畅销商品?",function(){
		layer.closeAll('dialog');
		var layer_load_window = layer.load(2); 
		var url=path+"/new_arrival_product/delete_by_id?ids="+id;
		$.ajax({
			url : url,
			cache : false,
			dataType : 'text',
			error : function() {
				layer.alert("操作失败！");
	       },
			success : function(data) {
			    if(data == "success"){
				    layer.msg('删除成功!',{icon:1,time:1000},function(){
				    	$("#search_form").submit();
				    });
			   }else if (data == "fail") {
				   layer.alert("操作失败！");
			   } else{
				layer.alert(data);
			   }
			},
			complete: function(XMLHttpRequest, textStatus) {
				layer.close(layer_load_window);
			}
		  })		
		});
}
function cancleSellWell(id){
	layer.confirm("确定要取消此畅销商品?",function(){
		submitSellWell(id,"");
	});
	}
function setSellWell(id,position){
	 layer.confirm("确定设置商品为新品？",function(){
			layer.closeAll('dialog');
			var layer_load_window = layer.load(2); 
			 $.ajax({
					url : path+"/new_arrival_product/check_up_new_product",
					cache : false,
					type : 'post',
					dataType : 'text',
					data:{position:position,id:id},
					error : function() {
						layer.alert("操作失败！");
			       },
					success : function(data) {
					    if(data == "yes"){
					    	layer.confirm("对不起，该位置上已经有畅销商品正在进行中了，确定要畅销该商品吗？",function(){
					    		submitSellWell(id,position);
					    	});
					   }else if(data == "no"){
							submitSellWell(id,position);
					   }else{
						layer.alert(data);
					   }
					},
					complete: function(XMLHttpRequest, textStatus) {
						layer.close(layer_load_window);
					}
				  })	
		 });
}
function submitSellWell(id,position){
			var layer_load_window = layer.load(2); 
			 $.ajax({
					url : path+"/new_arrival_product/update_by_id",
					cache : false,
					type : 'post',
					dataType : 'text',
					data:{position:position,id:id},
					error : function() {
						layer.alert("操作失败！");
			       },
					success : function(data) {
					    if(data == "success"){
						    layer.msg('设置成功!',{icon:1,time:1000},function(){
						    	$("#search_form").submit();
						    });
					   }else if(data == "fail"){
						layer.alert("操作失败！");
					   } else {
						   layer.alert(data);
					   }
					},
					complete: function(XMLHttpRequest, textStatus) {
						layer.close(layer_load_window);
					}
				  })	
}